package me.tuyou.mybatis.test.interfaces.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum Sex {
    MALE((byte) 0, "男性"),
    FEMALE((byte) 1, "女性");

    private byte code;
    private String text;

    public static Sex fromCode(byte code) {
        return Arrays.stream(Sex.values())
                .filter(item -> item.code == code)
                .findFirst()
                .orElse(null);
    }
}
